import { CARD} from "../../constant";
import { cardCache} from "nc-lightapp-front";
let { getDefData } = cardCache;
import { fiterDefdoc, fiterFrkm } from "../../../../common/util/fiterUtils";
import { DOCLIST } from "../../../../common/constant";
/**
* @description: 表头编辑前事件
* @param: moduleId 区域编码
* @param: key 当前字段编码
* @return: 布尔 true表示可编辑
*/
export function beforeHeadEvent(props, moduleId, key, value, data) {

        if('assdept' == key){

                let value = props.form.getFormItemsValue(CARD.form_id, 'accbank');

                if(value.value == ''){
                        props.form.setFormItemsDisabled(moduleId, {assdept:false});
                }else{
                        props.form.setFormItemsDisabled(moduleId, {assdept:true});
                }
        } else if("ass" == key ){
                let pk_accountingbook= getDefData("accbook","accbook");
                let pk_org = props.form.getFormItemsValue('card_head', 'pk_org').value;
                let fiterType = DOCLIST.qtsrjf;
                fiterFrkm(props, moduleId, key, pk_org, pk_accountingbook, fiterType);
        }else if('def1' == key){//管理科目
                //获取表单中的利润中心名称
            let center = props.form.getFormItemsValue(CARD.form_id, 'center').value;
            let where = "def1 in (select pk_org from org_orgs where dr=0 and name in (select name from org_orgs where pk_org='"+center+"')) and def7='Y'";
            fiterDefdoc(props, moduleId, key, where);
        }
        
        return true;
}